﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Client.ShopServiceReference;
using Server;
using ServerApp;

namespace Client
{
    class OrdersMock : IOrdersModel
    {

        /// <summary>
        /// Gets the list of the orders views
        /// </summary>        
        /// <param name="page">Number of the page</param>        
        /// <param name="filter">Dictionary<OrderFilter.value,object></param>
        /// <param name="numberOnThePage">Number of the orders on the one page</param>
        /// <returns>list of the orderView</returns> 
        public List<OrderView> GetOrders(Dictionary<OrderFilter, object> filter, int page, int numberOfOrders)
        {

            List<OrderView> list = new List<OrderView>();
            for (int i = 0; i < page * numberOfOrders; i++)
            {
                OrderView order = new OrderView(1* (i+1))
                {
                    CreatedDateTime = DateTime.Now,
                    Price = 20,
                    Status = OrderStatus.Created
                };

                OrderView order2 = new OrderView(2 * (i + 1))
                {
                    CreatedDateTime = DateTime.Parse("12.02.2012"),
                    Price = 1000,
                    Status = OrderStatus.Worked
                };

                OrderView order3 = new OrderView(3 * (i + 1))
                {
                    CreatedDateTime = DateTime.Parse("01.01.2009"),
                    Price = 900,
                    Status = OrderStatus.Closed
                };

                
                list.Add(order);
                list.Add(order2);
                list.Add(order3);
            }
            return list;
        }


        /// <summary>
        /// Gets the concrete order by its id
        /// </summary>
        /// <param name="id">Id of the order</param>
        /// <param name="language">Language</param>
        /// <returns>OrderFull value of the current order</returns>
        public OrderFull GetOrder(long id, string language)
        {
              Random rand = new Random();
            ProductView product = new ProductView(1)
            {
                CategoryId = 1,                
                Price = rand.Next(10000)
            };

            ProductView product2 = new ProductView(2)
            {
                CategoryId = 2,                
                Price = rand.Next(10000)
            };


            ///choosing the language
            switch (language)
            {
                case "en":
                    {

                        product.Name = "product" + rand.Next(10000); ;
                        product2.Name = "product" + rand.Next(10000); ;
                        break;
                    }
                case "ru":
                    {
                        product.Name = "продукт" + rand.Next(10000); ;
                        product2.Name = "продукт" + rand.Next(10000); ;
                        break;
                    }
            }

            User customer = null;
            switch(id)
            {
                case 1:
                    {
                        customer = new User(1)
                        {
                            Phone = "123123",
                            Login = "111",
                            Password = "111",
                            Role = Server.UserRole.Guest,
                            FIO = "customerFIO"
                        };
                        break;
                    }
                case 2:
                    {
                        customer = new User(2)
                        {
                            Phone = "123123",
                            Login = "2222",
                            Password = "2222",
                            Role = Server.UserRole.Guest,
                            FIO = "customerFIO2"
                        };
                        break;
                    }
                case 3:
                    {
                        customer = new User(3)
                        {
                            Phone = "123123",
                            Login = "3333",
                            Password = "3333",
                            Role = Server.UserRole.Guest,
                            FIO = "customerFIO3"
                        };
                        break;
                    }
                  
        }

            List<OrderPosition> orderPosition = new List<OrderPosition>();
            OrderPosition orderPositionItem = new OrderPosition(product, 1)
            {
                Cost = 200,
                Count = rand.Next(10),                
               // Product = product
            };

            OrderPosition orderPositionItem2 = new OrderPosition(product2, 1)
            {
                Cost = 400,
                Count = rand.Next(10),
                //OrderId = 1,
                //Product = product2
            };

            orderPosition.Add(orderPositionItem);
            orderPosition.Add(orderPositionItem2);

            m_currentOrder = new OrderFull(id)
            {                
                PlaceId = 1,
                Status = OrderStatus.Created,
                CreatedDateTime = DateTime.Now,
                Customer = customer,
                Composition = orderPosition
            };

            User executor = new User(3)
            {
                Phone = "12345",
                Login = "12345",
                Password = "12345",
                Role = Server.UserRole.Manager,
                FIO = "executorFIO"
            };

            ///order status
            switch(id)
            {
                case 1:
                    {
                        m_currentOrder.Status = OrderStatus.Created;
                        break;
                    }
                case 2:
                    {
                        m_currentOrder.Status = OrderStatus.Worked;
                        m_currentOrder.Executor = executor;
                        break;
                    }
                case 3:
                    {
                        m_currentOrder.Status = OrderStatus.Closed;
                        m_currentOrder.Executor = executor;
                        break;
                    }
            }
            
            return m_currentOrder;
        }


        /// <summary>
        /// Reserves the order (changes its status)
        /// </summary>
        /// <param name="orderId">order id</param>
        /// <param name="executorId">executor id</param>
        /// <returns>new OrderView value</returns>
        OrderFull  IOrdersModel.ReserveOrder(long orderId, long executorId)
        {
            User executor = new User(executorId)
            {
                FIO = "executor",
                Login = "executor",
                Password = "pass",
                Phone = "1111",
                Role = Server.UserRole.Manager
            };

            m_currentOrder.Executor = executor;
            m_currentOrder.Status = OrderStatus.Worked;
            return m_currentOrder;
        }


        /// <summary>
        /// Closes the order 
        /// </summary>
        /// <param name="orderId">order id</param>
        /// <returns>new OrderView value</returns>
        public OrderFull CloseOrder(long orderId)
        {
            throw new NotImplementedException();
        }


        /// <summary>
        /// Cancel the order and unreserves all products of this order
        /// </summary>
        /// <param name="orderId">Id of the order</param>
        /// <returns>bool value</returns>
        public bool CancelOrder(long orderId)
        {
            throw new NotImplementedException();
        }


        private OrderFull m_currentOrder;
    }
}
